<template>
  <demoBlock title="带斑马纹表格" padding>
    <vcu-table
      class="vcu-table-striped"
      :columns="columns"
      :datas="data"
      :rowClassName="
        (record, index) => (index % 2 === 1 ? 'table-striped' : null)
      "
      :cellClassName="
        (record, index, column) =>
          record.tags === '漂亮的' && column.dataIndex == 'tags'
            ? 'table-bg-blue'
            : null
      "
      bordered
    >
    </vcu-table>
  </demoBlock>
</template>

<script>
import { defineComponent, ref } from "vue";
const columns = [
  {
    title: "姓名",
    dataIndex: "name",
    key: "name",
  },
  {
    title: "年龄",
    dataIndex: "age",
    key: "age",
  },
  {
    title: "地址",
    dataIndex: "address",
    key: "address",
  },
  {
    title: "标签",
    key: "tags",
    dataIndex: "tags",
  },
];

const data = [
  {
    address: "火星",
    tags: "漂亮的",
    name: "张三",
    age: 32,
  },
  {
    name: "李四",
    age: 42,
    address: "地球",
    tags: "失败者",
  },
  {
    name: "王五",
    age: 32,
    address: "月亮",
    tags: "冰冷的",
  },
];
export default defineComponent({
  setup() {
    return {
      data,
      columns,
    };
  },
});
</script>
<style>
.vcu-table-striped .table-striped td {
  background-color: #fafafa;
}
.vcu-table-striped .vcu-table-body table td.table-bg-blue,
.vcu-table-striped .vcu-table-row td.table-bg-blue {
  background: blue;
  color: #fff;
}
</style>
